define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'manageuser.user/index',
        add_url: 'manageuser.user/add',
        edit_url: 'manageuser.user/edit',
        delete_url: 'manageuser.user/delete',
        export_url: 'manageuser.user/export',
        modify_url: 'manageuser.user/modify',
        adopt_url: 'manageuser.user/adopt_url',
    };
    var Controller = {
        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh'],
                cols: [[
                    {field: 'id', title: 'ID', search: false},
                    {field: 'nickname', title: '用户昵称'},
                  //  {field: 'referrer_user', title: '推荐人', search: false},
                    {field: 'avatar', minWidth: 80, title: '头像', search: false, templet: ea.table.image},
                    {field: 'gender', title: '性别',selectList: {0:'男',1: '女'}},
                    {field: 'is_check', title: '是否分销商',selectList: {0: '否',1: '是'}},
                    {field: 'commission', title: '可提现佣金', search: false},
                    {field: 'endmoney', title: '已提现佣金', search: false},
                    {field: 'is_realname', title: '是否实名',selectList: {0: '否',1: '是'}},
                    {field: 'idcard', title: '身份证号', search: false},
                    {field: 'real_name', title: '真实姓名', search: false},
                    {field: 'status', title: '用户状态', templet: ea.table.switch, search: false},
                    {field: 'service_technician_name', title: '达人', search: false},
                    {field: '', title: '是否达人', templet:function(d) {
                        if (d.service_technician_id == 0 ) {
                            return '<a class="layui-btn layui-btn-sm layui-btn-xs"  data-open="manageuser.user/binding_experts?id='+d.id+'" data-title="绑定达人" data-table="currentTableRenderId">绑定</a>';
                        }else{
                            return '<a class="layui-btn layui-btn-danger layui-btn-xs"  data-request="manageuser.user/unbinding_experts?id='+d.id+'" data-title="确定解绑吗？" data-table="currentTableRenderId">解绑</a>';
                        }
                    }},
                    {field: 'create_time', title: '注册时间', search: false},
                    {width: 250,title: '操作', templet: function (d) {
                            if(d.is_check == 1){
                                return '<button class="layui-btn layui-btn-normal layui-btn-sm layui-btn-disabled" >已是分销商</button>';
                            }else{
                                return '<button class="layui-btn layui-btn-xs layui-btn-normal" data-request="manageuser.user/adopt_url?id='+d.id+'"  data-title="确定成为分销商吗？" >成为分销商</button>'
                            }
                        }
                    },
                ]],
            });
            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        binding_experts: function () {
            ea.listen();
        }
    };
    return Controller;
});